package dico.finder.impl;

import java.util.Arrays;

import dico.finder.Word;
import dico.finder.WordType;
import dico.finder.tool.StringOperation;

public class SimpleWord implements Word {
  
	/**
	 * the word as a string
	 */
	private String string_word;
	
	/**
	 * the type of the word
	 */
	private WordType word_type;
	
	/**
	 * the word in the alphabetical order
	 */
	private String alphabetical_order;
	
	/**
	 * the word used to make a search
	 */
	private String finder_word;
	
	/**
	 * create a simple word
	 * 
	 * @param word the string word
	 * @param type the type of the string
	 */
	public SimpleWord(String word, WordType type) {
		this.word_type = type;
		this.string_word = word;
		/** create the list to be sorted */
		char[] chars = word.toCharArray();
		Arrays.sort(chars);
		this.alphabetical_order = new String(chars);
		this.createFinderWord();
	}
	
	/**
	 * create a simple word
	 * 
	 * @param word the string word
	 * @param type the type of the string
	 * @param alphabetical_order the word in the alphabetical order Name => ANME
	 */
	public SimpleWord(String word, WordType type, String alphabetical_order) {
		this.word_type = type;
		this.string_word = word;
		this.alphabetical_order = alphabetical_order;
		this.createFinderWord();
	}
	
	/**
	 * create the finder word
	 */
	private void createFinderWord()
	{
		this.finder_word = StringOperation.transform(this.string_word, StringOperation.LOWER_CASE | StringOperation.WITHOUT_ACCENTS);
	}
	
	@Override
	public String getWord() {
		return this.string_word;
	}

	@Override
	public WordType getType() {
		return this.word_type;
	}

	@Override
	public String getAlphabeticalOrder() {
		return this.alphabetical_order;
	}
	
	@Override
	public String toString() {
		return this.string_word+"("+this.word_type+")";
	}

	@Override
	public String getFinderWord() {
		return this.finder_word;
	}
}
